package com.gupao.singleton;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @Description: //TODO:
 * @ClassName: FactorySigletonTest
 * @Author: msx
 * @CreateDate: 2018/3/23 11:53
 */
public class FactorySigletonTest {

    public static void main(String[] args) {

        int count = 20;
        /*final CountDownLatch latch  = new CountDownLatch(count);
        for (int i = 0; i < count; i++) {
            new Thread(new Runnable() {
                public void run() {
                    //主线程，等待。。。。
                    try {
                        System.out.println("主线程，等待。。。。");
                        latch.await();
                        LoggerFactory factory = LoggerFactorySingleton.getLoggerFactoryInstance();
                        System.out.println("工厂单列："+factory.userLoginLogger(new Logger()));
                    } catch (Exception e) {
                    	// TODO: handle exception
                    	e.printStackTrace();
                    }
                }
            }).start();

            //每次启动一个线程，count --
            latch.countDown();
        }*/
        List<ThreadClass> threadList = new ArrayList<ThreadClass>();
        for (int i = 0; i < count; i++) {
            ThreadClass thread = new ThreadClass();
            try {
                System.out.println("线程等待。。。。");
                thread.join();
                threadList.add(thread);
            } catch (Exception e) {
            	// TODO: handle exception
            	e.printStackTrace();
            }
        }
        for (ThreadClass thread : threadList) {
            thread.start();
        }
    }


    public static class ThreadClass extends  Thread{
        public void run(){
            LoggerFactory factory = LoggerFactorySingleton.getLoggerFactoryInstance();
            System.out.println("工厂单列："+factory.userLoginLogger(new Logger())+factory);
        }
    }
}
